#include "television.h"
#include <iostream>

using namespace std;


Television * const Television::p = new Television;


Television::Television()
{
    // 无参构造
    this->mState = CLOSE;
    this->mVolume = MIN_VOLUME;
    this->mChannel = MIN_CHANNEL;
}

Television::Television(int stat, int vol, int chn)
{
    // 有参构造
    this->mState = stat;
    this->mVolume = vol;
    this->mChannel = chn;
}

Television::Television(const Television &ob)
{
    // 拷贝构造
    this->mState = ob.mState;
    this->mVolume = ob.mVolume;
    this->mChannel = ob.mChannel;
}

Television::~Television()
{
    // 析构函数
    cout << "析构函数" << endl;
}


SmartPointer::SmartPointer()
{
    // 智能指针无参构造
    this->p = NULL;
}

SmartPointer::SmartPointer(Television *p)
{
    // 智能指针有参构造
    this->p = p;
}

SmartPointer::~SmartPointer()
{
    // 智能指针析构函数
    delete p;
}



Television *Television::pushPointer(void)
{
    return p;
}

Television *Television::operator->()
{
    return this;
}

Television Television::operator*()
{
    return *this;
}

void Television::showTelevision(void)
{
    if (this->mState)
    {
        cout << "电视机状态：开" << endl;
    }
    else
    {
        cout << "电视机状态：关" << endl;
    }

    cout << "电视机音量：" << this->mVolume << endl;
    cout << "电视机频道：" << this->mChannel << endl;
    cout << endl;

    return;
}

void Television::changeState(void)
{
    switch(mState)
    {
        case 0:
            mState = OPEN;
            break;
        case 1:
            mState = CLOSE;
            break;
        default:
            break;
    }

    return;
}

void Television::increaseVolume(void)
{   
    // 判断
    if (this->mVolume == MAX_VOLUME)
    {
        return;
    }
    else 
    {
        this->mVolume++;
    }


    return;
}

void Television::decreaseVolume(void)
{
    // 判断
    if (this->mVolume == MIN_VOLUME)
    {
        return;
    }
    else 
    {
        this->mVolume--;
    }


    return;
}
void Television::increaseChannel(void)
{
    // 判断
    if (this->mChannel == MAX_CHANNEL)
    {
        return;
    }
    else 
    {
        this->mChannel++;
    }


    return;
}

void Television::decreaseChannel(void)
{
    // 判断
    if (this->mChannel == MIN_CHANNEL)
    {
        return;
    }
    else 
    {
        this->mChannel--;
    }


    return;
}

void Control::setState(Television *p, bool st)
{
    switch(st)
    {
        case 0:
            p->mState = p->CLOSE;
            break;
        case 1:
            p->mState = p->OPEN;
            break;
        default:
            break;
    }

    return;
}
void Control::setVolume(Television *p, int vol)
{
    if (vol < p->MIN_VOLUME || vol > p->MAX_VOLUME)
    {
        return;
    }
    p->mVolume = vol;


    return;
}

void Control::setChannel(Television *p, int chn)
{
    if (chn < p->MIN_CHANNEL || chn > p->MAX_CHANNEL)
    {
        return;
    }
    p->mChannel = chn;


    return;
}

void Control::showTelevision(Television *p)
{
    p->showTelevision();
    return;
}

void Control::changeState(Television *p)   
{
    p->changeState();
    return;
}  
void Control::increaseVolume(Television *p)   
{
    p->increaseVolume();
    return;
}
void Control::decreaseVolume(Television *p)     
{
    p->decreaseVolume();
    return;
}
void Control::increaseChannel(Television *p)     
{
    p->increaseChannel();
    return;
}
void Control::decreaseChannel(Television *p)   
{
    p->decreaseChannel();
    return;
}  
